<template>
  <div class="event-select full">
    <div class="selectbox">
      <el-select style="width:100%;height:100%;" v-model="currentId" placeholder="选择事件">
        <el-option
          v-for="(item,index) in eventDataList"
          :label="item.NAME"
          :value="item.CODE"
          :key="index"
        ></el-option>
      </el-select>
    </div>

    <div class="endbox btnbox">
      <div class="centerbox" @click="clickSetEvent">配置</div>
      <div class="centerbox" @click="openClickEvent">打开</div>
    </div>
    <el-dialog title="事件联动配置" :visible.sync="showEventPopup" width="9.2rem">
      <popup  v-if="showEventPopup" @close='close' />
      <iframe class="iframe" frameborder=0></iframe>
    </el-dialog>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import popup from "./EventPopus.vue";
interface eventItem {
  CODE: string;
  NAME: string;
}
@Component({ components: { popup } })
export default class extends Vue {
  // 选择事件的id
  currentId: string = "";
  // 是否显示事件联动弹窗
  showEventPopup: boolean = false;
  // 事件数据集合
  eventDataList: eventItem[] = [];
  mounted() {
    this.storyList();
  }
  // 关闭弹窗
  close(){
    this.showEventPopup=false
  }
  // 获取事件配置列表
  storyList() {
    (this as any).$services
      .storyList()
      .then((result: any) => {
        if (result.data.length) {
          this.eventDataList = result.data;
        } else {
          this.eventDataList = [];
        }
      })
      .catch((err: object) => {
        console.log(err);
        this.eventDataList = [];
      });
  }

  // 打开
  openClickEvent() {
    this.$emit("openClickEvent", this.currentId);
  }
  // 配置
  clickSetEvent() {
    this.showEventPopup = true;
  }
}
</script>

<style lang="scss" scoped>
.event-select {
  padding: 0.1rem;
  box-sizing: border-box;
  .selectbox {
    width: 100%;
    height: 0.5rem;
  }
  .btnbox {
    > div {
      border: 1px solid #04b0f0;
      border-radius: 4px;
      margin-left: 0.1rem;
      width: 0.6rem;
      height: 0.3rem;
      cursor: pointer;
      transition: all 500ms;
    }
    > div:hover {
      background: #05b4ff;
    }
  }
  .iframe {
    width: 100vw;
    height: 100vh;
    position: fixed;
    top: 0px;
    left: 0px;
    z-index: 1;
    opacity: 0.1;
    background: none;
    pointer-events: none;
  }
}
</style>

